package io.seata.samples.sb.tccat.db.controller;

import io.seata.samples.sb.tccat.api.model.User;
import io.seata.samples.sb.tccat.api.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {
    private final UserService userService;

    @PostMapping("/saveOrUpdate")
    public User saveOrUpdate(@RequestBody User user) {
        boolean saveOrUpdate = userService.saveOrUpdate(user);
        return user;
    }

    @GetMapping("/removeById/{id}")
    public boolean delete(@PathVariable(value = "id") Long id) {
        return userService.removeById(id);
    }

    @GetMapping("/getById/{id}")
    public User findById(@PathVariable(value = "id") Long id) {
        return userService.getById(id);
    }

    @GetMapping("/list")
    public List<User> list() {
        return userService.list();
    }
}
